home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11482 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: void ** question
  5. Date: Sun, 24 Mar 96 14:53:28 GMT
  6. Organization: none
  7. Message-ID: <827679208snz@genesis.demon.co.uk>
  8. References: <DoJBrL.F5t@bear.wn.bawue.de> <4iue80$btk@transformer.pti-us.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4iue80$btk@transformer.pti-us.com>
  15.            wv.dixon@pti-us.com "Walt Dixon" writes:
  16.  
  17. >I am not sure it is legal.  void* is an anonymous type,
  18.  
  19. No, void * is a single type just like long or int *. It is a pointer to
  20. an incomplete type (since void has no size) so, for example, you can't
  21. perform pointer arithmetic on it. void isn't the only incomplete type,
  22. (int []) or (struct foo) where no member list for foo is visible are other
  23. examples.
  24.  
  25. The unique property of void * is that you can convert any pointer (except
  26. pointers to functions) to void * and back again without using a cast (except
  27. for const/volatile qualifier considerations), and you'll get back a pointer
  28. that compares equal to the one you started with. The representation of
  29. void * may be different to other pointers (except char *) so when I say
  30. 'convert' above a change of representation may really occur (and on some
  31. systems it does).
  32.  
  33. >not void**.  
  34.  
  35. void ** is a normal object pointer with no special properties. It can legally
  36. hold a null pointer or a pointer to a void * object, but that's all.
  37.  
  38. >Your program should work if you change void f(void**) to void f(void*).  
  39. >It will then be up to you to cast the void* argument to f to the proper type
  40. >in your case (int**)).  Since void* is an anonymous type, the conversion
  41.  
  42. If the context determines the target type the cast is unnecessary.
  43.  
  44. >between
  45. >int** and void* will occur automatically.  No casting will be necessary
  46. >when calling function f.
  47. >
  48. >
  49. >void f(void* x)
  50. >{
  51. >   int** y = (int**)x;
  52.  
  53. The cast here is unnecessary.
  54.  
  55. >}
  56. >
  57. >int main(void)
  58. >{
  59. >    int **ppi;
  60. >    f(ppi)
  61.  
  62. As it stands this is illegal since it tries to pass the value of an
  63. uninitialised variable as an argument. You could write something like:
  64.  
  65.      int *pi;
  66.      f(&pi)
  67.  
  68. >    return 0;
  69. >}
  70. >
  71. >
  72.  
  73. -- 
  74. -----------------------------------------
  75. Lawrence Kirby | fred@genesis.demon.co.uk
  76. Wilts, England | 70734.126@compuserve.com
  77. -----------------------------------------
  78.